package com.xingda.packing.task.listener;

import com.xingda.packing.domain.PackProductionLine;
import com.xingda.packing.enums.TaskState;
import com.xingda.packing.enums.TaskType;
import com.xingda.packing.task.ticket.ScanCodeTicket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ScanCodeListener implements TaskListenerService {

    @Override
    public boolean accept(PackProductionLine productionLine, int area) {
        return checkTask(productionLine.getRobot().getTaskTicket(area), TaskType.SCANCODE);
    }

    @Override
    public void monitor(PackProductionLine productionLine, int area) {
        if (productionLine.getRobot().isGrabComplete(area)) {
            ScanCodeTicket ticket = (ScanCodeTicket) productionLine.getRobot().getTaskTicket(area);
            //productionLine.getRobot().getEventCreater().createFinishPkAction(ActionType.SCAN_CODE,area);
            ticket.setState(TaskState.FINISH);
            productionLine.getRobot().resetStatus(area);
            productionLine.getRobot().listenerScanCodeEvent(ticket, area);
        }
    }
}
